﻿<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="LogManager.ascx.cs" Inherits="FreshCms.BackEnd.Controls.Systems.Log.LogManager" %>
<%@ Register Src="~/BackEnd/ControlsCommon/Pager.ascx" TagName="Pager" TagPrefix="uc" %>

<div id="page-content" class="block">
    <div class="block-header">
        <a href="javascript:void(0)" class="header-title-link">
            <h1>Hệ thống Log</h1>
        </a>
    </div>

    <div class="col-sm-2"></div>
    <div class="col-sm-9">
        <div class="block">
            <div class="block-title"><h2>Chức năng</h2></div>
            <div class="col-sm-12">
                <div class="col-sm-6">
                    <div class="form-group">
                        <div class="input-group">
                            <span class="input-group-addon"><i class="gi gi-envelope"></i></span>
                            <input type="text" id="txtMail" class="form-control" value="<%=mail %>">
                            <span class="input-group-addon">Email</span>
                        </div>
                    </div>
                    <div class="form-group">
                        <div class="input-group">
                            <span class="input-group-addon"><i class="gi gi-calendar"></i></span>
                            <input type="text" id="txtFrom" class="form-control input-datepicker-close text-center" data-date-format="dd/mm/yyyy" placeholder="dd/mm/yyyy" value="<%=from %>">
                            <span class="input-group-addon">Ngày bắt đầu</span>
                        </div>
                    </div>
                </div>
                <div class="col-sm-6">
                    <div class="form-group">
                        <div class="input-group">
                            <span class="input-group-addon"><i class="gi gi-electricity"></i></span>
                            <asp:DropDownList ID="ddlAction" runat="server" CssClass="form-control" size="1"></asp:DropDownList>
                            <span class="input-group-addon">Thao tác</span>
                        </div>
                    </div>
                    <div class="form-group">
                        <div class="input-group">
                            <span class="input-group-addon"><i class="gi gi-calendar"></i></span>
                            <input type="text" id="txtTo" class="form-control input-datepicker-close text-center" data-date-format="dd/mm/yyyy" placeholder="dd/mm/yyyy" value="<%=to %>">
                            <span class="input-group-addon">Ngày kết thúc</span>
                        </div>
                    </div>
                </div>
            </div>

            <div class="form-group text-center">
                <button type="button" id="btnSearch" class="btn btn-sm btn-info"><i class="gi gi-search mr5"></i>Tìm kiếm</button>
                <button type="button" id="btnDelete" class="btn btn-sm btn-warning"><i class="gi gi-remove_2 mr5"></i>Xóa Log</button>
                <div class="btn-group dropup text-left">
                    <a href="javascript:void(0)" data-toggle="dropdown" class="btn btn-sm btn-danger dropdown-toggle"><i class="gi gi-remove_2"></i> Xóa toàn bộ Log</a>
                    <ul class="dropdown-menu dropdown-menu-delete">
                        <li><a href="javascript:void(0)" onclick="DeleteAll()">Đồng ý</a></li>
                        <li><a href="javascript:void(0)">Hủy</a></li>
                    </ul>
                </div>
            </div>
        </div>
    </div>

    <div class="table-responsive">
        <table id="tblPms" class="table table-hover">
            <thead>
                <tr>
                    <th class="text-center" style="width: 30px;"><input type="checkbox" id="chkAll" /></th>
                    <th class="text-center" style="width: 30px;">#</th>
                    <th class="text-center" style="width: 60px;">Id</th>
                    <th style="width: 100px;">Email</th>
                    <th>Log 1</th>
                    <th>Log 2</th>
                    <th>Log 3</th>
                    <th>Thời gian</th>
                </tr>
            </thead>
            <tbody>
                <asp:Repeater ID="rpt" runat="server">
                    <ItemTemplate>
                        <tr>
                            <td class="text-center" style="width: 30px;"><input type="checkbox" id="chk_<%# Eval("LogId")%>" name="<%# Eval("LogId")%>" rel='chkLog' /></td>
                            <td class="text-center"><%# Container.ItemIndex + 1 %></td>
                            <td class="text-center"><%# Eval("LogId")%></td>
                            <td><%# Eval("UserMail")%></td>
                            <td><%# Eval("Field1")%></td>
                            <td><%# Eval("Field2")%></td>
                            <td><%# Eval("Field3")%></td>
                            <td><%# String.Format("{0:dd/MM/yyyy}", Eval("LogDate"))%><span style="font-size: 11px;color: #999;padding-left: 5px;font-style: italic;">(<%# String.Format("{0:hh:mm:ss}", Eval("LogDate"))%>)</span></td>
                        </tr>
                    </ItemTemplate>
                </asp:Repeater>
            </tbody>
        </table>
    </div>
    <div class="text-center">
        <uc:Pager ID="Pager" runat="server" />
    </div>
</div>
<script>
    $("#chkAll").click(function () {
        if ($("#chkAll").is(':checked')) {
            $("#tblPms input:checkbox[id*='chk_']").each(function () {
                $(this).prop("checked", true);
            });

        } else {
            $("#tblPms input:checkbox[id*='chk_']").each(function () {
                $(this).prop("checked", false);
            });
        }
    });

    $("#btnDelete").bind("click", function() {
        var lstChecked = '';
        $("#tblPms input:checkbox[id*='chk_']").each(function () {
            if ($(this).is(':checked')) {
                lstChecked = lstChecked + $(this).attr('name') + ',';
            }
        });
        if (lstChecked != '') {
            lstChecked = lstChecked.substring(0, lstChecked.length - 1);
            //console.log(lstChecked);    
            
            // call ajax delete log
            var param;
            param = {
                m: "delete",
                ui : <%=panelId %>,
                lst: lstChecked
            };
            $.ajax({
                url: "/BackEnd/Handler/Log.ashx",
                data: param,
                type: "POST",
                dataType: "json",
                beforeSend: function () {
                    jWaiting.callWaiting();
                },
                success: function (data) {
                    //console.log(data);
                    if (data.Success) {
                        jWaiting.callWaitingMessSuccess('Xóa Log đã chọn thành công...', 'reload', true);
                    }
                    else {
                        jWaiting.callWaitingMessError(data.Message);
                    }
                }
            });
        }else {
            jWaiting.callWaitingMessError('Bạn chưa chọn Log để xóa.');
        }
        
    });
    

    
    
    
    $("#btnSearch").bind("click", function () {
        var link = '/BackEnd/?ui=4';
        if($('#txtMail').val().length>0) link = link + '&mail=' + $('#txtMail').val();
        if($('#txtFrom').val().length>0) link = link + '&from=' + $('#txtFrom').val();
        if($('#txtTo').val().length>0) link = link + '&to=' + $('#txtTo').val();
        link = link + '&action=' + $('#<%=ddlAction.ClientID %>').val();
        window.location.href = link;
    });

    // event Delete All Log
    function DeleteAll() {
        // call ajax
        var param;
        param = {
            m: "deleteall",
            ui : <%=panelId %>
        };
        $.ajax({
            url: "/BackEnd/Handler/Log.ashx",
            data: param,
            type: "POST",
            dataType: "json",
            beforeSend: function () {
                jWaiting.callWaiting();
            },
            success: function (data) {
                //console.log(data);
                if (data.Success) {
                    jWaiting.callWaitingMessSuccess('Xóa toàn bộ Log Hệ Thống thành công...', 'reload', true);
                }
                else {
                    jWaiting.callWaitingMessError(data.Message);
                }
            }
        });
    }
</script>